<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性的复杂操作</title>
</head>
<body>
    <div id="app">
        总价格:{{totalPrice}}
    </div>

    <script src="../vue/vue.js"></script>
    <script>
        const app = new Vue({
            el:'#app',
            data:{
                books:[
                    {id:110,name:'现代javaScript教程',price:199},
                    {id:111,name:'JavaScript高级程序设计',price:99},
                    {id:112,name:'JavaScript高级鉴赏',price:94},
                    {id:113,name:'你不知道的JavaScript',price:78}
                ]
            },
            computed:{
                totalPrice(){
                    numPrice = 0;
                    this.books.forEach(element => {
                        numPrice += element.price
                    });
                    return numPrice
                }
            }
        });
    </script>
</body>
</html>